package com.medicine.hbp.dialog;

import java.util.ArrayList;
import java.util.List;

import com.medicine.hbp.R;

import android.app.Activity;
import android.app.Dialog;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

public class PayDialog implements OnItemClickListener {

	private Activity activity;

	private Dialog dialog;

	private PayDialogListener listener;



	public PayDialog(Activity activity, PayDialogListener listener) {
		this.activity = activity;
		this.listener = listener;
	}

	public void showPayDialog() {
		List<String> photographList = new ArrayList<String>();
//		if(state==0){
		photographList.add("支付宝");
		photographList.add("微信");
//		}else if(state==1){
//			photographList.add("拍照");
//		}else if(state==2){
//			photographList.add("从手机相册中选择");
//		}

		View view = activity.getLayoutInflater().inflate(
				R.layout.photograp_dialog, null);
		ListView listView = (ListView) view.findViewById(R.id.listView);
		listView.setAdapter(new ArrayAdapter(activity,
				R.layout.photograp_dialog_item, R.id.nameText, photographList));

		listView.setOnItemClickListener(this);

		dialog = new Dialog(activity, R.style.transparentFrameWindowStyletwo);
		dialog.setContentView(view, new LayoutParams(LayoutParams.MATCH_PARENT,
				LayoutParams.WRAP_CONTENT));
		Window window = dialog.getWindow();

		Button button_cancle = (Button) view
				.findViewById(R.id.button_cancle_three);

		// 取消操作
		button_cancle.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				dialog.dismiss();
				if (listener != null) {
					listener.onCancel();
				}
			}
		});
		// 设置显示动画
		window.setWindowAnimations(R.style.show_photograpDialog_animstyle);
		WindowManager.LayoutParams wl = window.getAttributes();
		wl.x = 0;
		wl.y = activity.getWindowManager().getDefaultDisplay().getHeight();
		wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
		wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;
		dialog.onWindowAttributesChanged(wl);
		dialog.setCanceledOnTouchOutside(true);
		dialog.show();
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		dialog.dismiss();
		if (listener != null) {
			listener.onSelect(arg2);
		}
	}

	public interface PayDialogListener {
		public void onSelect(int broadband);

		public void onCancel();
	}
}